//
//  OpenCell.m
//  Gunterapple
//
//  Created by 热带雨林 on 2020/3/18.
//  Copyright © 2020 热带雨林. All rights reserved.
//

#import "OpenCell.h"
#import "UIView+ML_Extension.h"
#import "OpenCellButtonView.h"
#import "GAButtonViewController.h"
//BOOL isClick;

@interface OpenCell()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIButton *typeBtn;
@property (nonatomic, strong) UILabel *descLab;
@property (nonatomic, strong) UIImageView *imaView;

@property (nonatomic, strong) OpenCellButtonView *buttonView;

@property (nonatomic, strong) GDButton *likeBtn;
@property (nonatomic, strong) GDButton *commentBtn;
@property (nonatomic, strong) GDButton *camereBtn;
@property (nonatomic, strong) UIButton *testButton;
//@property (nonatomic, strong) UIImageView *startImg;
@property (nonatomic, strong) UILabel *testLabel;

//@property (nonatomic, strong) UIStackView *btnStackView;

@end

@implementation OpenCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initLayout];
    }
    return self;
}
#pragma mark - 布局子控件
- (void)initLayout{
    self.contentView.backgroundColor = [UIColor clearColor];
    self.bgView = [[UIView alloc]initWithFrame:CGRectMake(14, 0, 386, 115)];
    //不能使用contentView ，如果使用之后滚动时cell会消失
    [self addSubview:self.bgView];
//    [self.contentView addSubview:self.bgView];
    self.bgView.backgroundColor = NormalColor;
    self.bgView.layer.cornerRadius = 10.0f;
    self.bgView.clipsToBounds = YES;
    
    //设置背景图片，但是不能设置填充方式
//    UIImage *img = [UIImage imageNamed:@"openImage"];
//    self.bgView.layer.contents = (id)img.CGImage;
    //
    
    self.imaView = [[UIImageView alloc]initWithFrame:CGRectZero];
    [self.bgView addSubview:self.imaView];
    self.imaView.layer.cornerRadius = 10.0f;
    self.imaView.layer.masksToBounds = YES;
    self.imaView.image = [UIImage imageNamed:@"armImg18"];
    self.imaView.contentMode = UIViewContentModeScaleAspectFill;
    self.imaView.clipsToBounds = YES;
    [self.imaView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView).offset(10);
        make.left.equalTo(self.bgView).offset(10);
        make.size.mas_equalTo(CGSizeMake(100, 150));
    }];
    
    self.titleLab = [[UILabel alloc]init];
    [self.bgView addSubview:self.titleLab];
//    self.titleLab.tintColor = [UIColor blackColor];
    self.titleLab.textColor = [UIColor whiteColor];
    self.titleLab.font = [UIFont fontWithName:Helvetica size:20];
    self.titleLab.textAlignment = NSTextAlignmentLeft;
    self.titleLab.numberOfLines = 0;
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView).offset(20);
        make.left.equalTo(self.imaView.mas_right).offset(20);
//        make.right.equalTo(self.bgView.mas_right).offset(-20);
        make.width.mas_lessThanOrEqualTo(200);
    }];
    
    //详情介绍
    self.descLab = [[UILabel alloc]init];
    [self.bgView addSubview:self.descLab];
    self.descLab.textColor = [UIColor whiteColor];
    self.descLab.font = [UIFont systemFontOfSize:14];
    self.descLab.textAlignment = NSTextAlignmentLeft;
    self.descLab.numberOfLines = 5;
    [self.descLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLab.mas_bottom).offset(10);
        make.left.equalTo(self.titleLab);
        make.right.equalTo(self.mas_right).offset(-20);
//        make.bottom.equalTo(self.bgView.mas_bottom).offset(-20);
    }];
    self.testLabel = [[UILabel alloc]init];
    self.testLabel.hidden = YES;
    self.testLabel.text = @"NIHAO";
    [self addSubview:self.testLabel];
    [self.testLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.descLab.mas_bottom).offset(5);
        make.left.equalTo(self.descLab);
    }];
    
    //
    self.typeBtn = [[UIButton alloc]initWithFrame:CGRectZero];
    [self.bgView addSubview:self.typeBtn];
    [self.typeBtn setImage:[UIImage imageNamed:@"btn_close"] forState:UIControlStateNormal];
    [self.typeBtn addTarget:self action:@selector(closeMemoryView:) forControlEvents:UIControlEventTouchUpInside];
    [self.typeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView).offset(5);
        make.right.equalTo(self.bgView.mas_right).offset(-20);
        make.width.height.mas_equalTo(34);
    }];

    self.buttonView = [[OpenCellButtonView alloc]initWithFrame:CGRectZero];
    [self addSubview:self.buttonView];
    [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imaView.mas_bottom).offset(27);
        make.left.equalTo(self.imaView);
        make.size.mas_equalTo(CGSizeMake(300, 40)); //此处是可以设置视图尺寸
    }];
    
    //此处的按钮布局 使用stackView不能解决问题！！！
    
//    self.btnStackView = [[UIStackView alloc]initWithArrangedSubviews:@[self.likeBtn,self.camereBtn,self.commentBtn]];
//    [self addSubview:self.btnStackView];
//    self.btnStackView.spacing = 5.0f;
//    self.btnStackView.axis = UILayoutConstraintAxisHorizontal;
//    self.btnStackView.distribution = UIStackViewDistributionFillEqually;
//    self.btnStackView.alignment = UIStackViewAlignmentFill;
//    [self.btnStackView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.imaView.mas_bottom).offset(10);
//        make.left.equalTo(self.imaView);
//        make.size.mas_equalTo(CGSizeMake(300, 40));
//    }];
    
    //
    self.height = 240;
    [self.bgView setHeight:self.height];

    if(isClick == YES)
        self.testLabel.hidden = NO;
    else
        self.testLabel.hidden = YES;
        
}

- (void)closeMemoryView:(UIButton *)sender{
    //注意：
    [self.indexArr removeObject:[NSString stringWithFormat:@"%d",self.index]];
    if([self.delegate respondsToSelector:@selector(baseCell:withBtnType:withIndex:withArray:)]){
            [self.delegate baseCell:self withBtnType:CLOSE withIndex:self.index withArray:self.indexArr];
    }
}
- (void)setModel:(openOrCloseModel *)model{
    self.titleLab.text = model.tipStr;
    self.descLab.text = model.descStr;
//    self.descLab.text = @"素胚勾勒出青花笔锋浓转淡 瓶身描绘的牡丹一如你初妆 冉冉檀香透过窗心事我了然 宣纸上走笔至此搁一半 釉色渲染仕女图韵味被私藏 而你嫣然的一笑如含苞待放 你的美一缕飘散 去到我去不了的地方 天青色等烟雨 而我在等你 炊烟袅袅升起 隔江千万里 在瓶底书汉隶仿前朝的飘逸 就当我为遇见你伏笔 天青色等烟雨 而我在等你 月色被打捞起 晕开了结局 如传世的青花瓷自顾自美丽";
}


- (void)setView:(openOrCloseModel *)model{
//    self.titleLab.text = model.tipStr;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
